﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.InventoryUI {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import Display.*;
    import Display.MarketUI.*;
    import GameMode.*;
    import flash.text.*;
    import Display.aswingui.*;
    import L10n.*;
    import Display.WishlistUI.*;

    public class InventoryCatalogUI extends ItemCatalogUI implements ICatalogUI {

        public static const CATALOG_TOTAL_WIDTH:int = 560;
        public static const INVENTORY_TITLE_WIDTH:int = 490;
        public static const INVENTORY_CLOSE_BUTTON_WIDTH:int = 36;
        public static const TOP_INSET_HEIGHT:int = 0;
        public static const CENTER_PANEL_MARGIN:int = 25;
        public static const INVENTORY_TITLE_FONT_SIZE:Number = 32;

        protected var m_catalogTitle:String;
        protected var m_doHighlight:Boolean = false;
        protected var m_wishlistPane:WishlistView;

        public function InventoryCatalogUI(){
            this.mouseEnabled = (this.mouseChildren = true);
            this.m_catalogTitle = ZLoc.t("Dialogs", "InventoryTitle");
        }
        protected function get assets():Dictionary{
            return (InventoryView.assetDict);
        }
        protected function get wishListGap():int{
            return (16);
        }
        override public function init(_arg1:String, _arg2:Catalog, _arg3:String, _arg4:Boolean, _arg5:String):void{
            this.makeBackground();
            this.m_containerWidth = CATALOG_TOTAL_WIDTH;
            this.m_catalog = _arg2;
            this.m_type = _arg1;
            m_topPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            m_topLeftPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            m_tabsPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            m_centerPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT);
            this.makeTopTabs();
            this.append(m_topPanel);
            this.append(ASwingHelper.verticalStrut(this.wishListGap));
            this.append(m_centerPanel);
            ASwingHelper.prepare(this);
            m_catalog.addEventListener(MouseEvent.MOUSE_DOWN, this.onInventoryDown, false, 0, true);
            m_catalog.addEventListener(MouseEvent.MOUSE_MOVE, this.onInventoryDown, false, 0, true);
            m_catalog.addEventListener(MouseEvent.MOUSE_OVER, this.onInventoryOver, false, 0, true);
            m_catalog.addEventListener(MouseEvent.MOUSE_OUT, this.onInventoryOut, false, 0, true);
            this.switchType(_arg1);
            addListeners();
        }
        override protected function makeTopTabs(_arg1:Array=null):void{
            m_topLeftPanel.append(ASwingHelper.horizontalStrut(INVENTORY_CLOSE_BUTTON_WIDTH));
            m_topLeftPanel.append(this.makeTitlePanel());
            m_topLeftPanel.append(this.makeCloseButtonPanel());
            m_tabsPanel.append(ASwingHelper.horizontalStrut(this.wishListTab));
            m_tabsPanel.append(this.makeWishlistPanel());
            m_topPanel.append(ASwingHelper.verticalStrut(-5));
            m_topPanel.append(m_topLeftPanel);
            m_topPanel.append(ASwingHelper.verticalStrut(-15));
            m_topPanel.append(m_tabsPanel);
            ASwingHelper.prepare(m_topPanel);
        }
        protected function get wishListTab():int{
            return (40);
        }
        protected function get showInventory():Boolean{
            return (true);
        }
        protected function makeWishlistPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            this.m_wishlistPane = new WishlistView(this.showInventory);
            ASwingHelper.prepare(this.m_wishlistPane);
            _local1.append(this.m_wishlistPane);
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        protected function makeCloseButtonPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local2:DisplayObject = (new (this.assets["btn_close_big_up"])() as DisplayObject);
            var _local3:DisplayObject = (new (this.assets["btn_close_big_down"])() as DisplayObject);
            var _local4:DisplayObject = (new (this.assets["btn_close_big_over"])() as DisplayObject);
            m_closeButton = new JButton();
            m_closeButton.wrapSimpleButton(new SimpleButton(_local2, _local4, _local3, _local2));
            m_closeButton.addActionListener(closeCatalog, 0, true);
            _local1.append(ASwingHelper.verticalStrut(this.closeButtonGapFromTop));
            _local1.append(m_closeButton);
            return (_local1);
        }
        protected function get closeButtonGapFromTop():int{
            return (5);
        }
        protected function makeTitlePanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local2:int = INVENTORY_TITLE_FONT_SIZE;
            var _local3:JTextField = ASwingHelper.makeTextField(this.m_catalogTitle, EmbeddedArt.TITLE_FONT, _local2, 16508714);
            var _local4:TextFormat = new TextFormat();
            _local4.align = TextFormatAlign.CENTER;
            _local4.size = (INVENTORY_TITLE_FONT_SIZE + 12);
            TextFieldUtil.formatSmallCaps(_local3.getTextField(), _local4);
            _local3.setPreferredWidth(this.titleWidth);
            if (this.m_doHighlight){
                _local3.filters = EmbeddedArt.newtitleFilters;
            } else {
                _local3.filters = [new GlowFilter(33724, 1, 6, 6, 6)];
            };
            LocaleHelper.localSetting.ASwingHelper_setEasyBorder(_local1, 6);
            _local1.append(_local3, SoftBoxLayout.CENTER);
            return (_local1);
        }
        protected function get titleWidth():int{
            return (INVENTORY_TITLE_WIDTH);
        }
        override protected function makeBackground():void{
            var _local1:DisplayObject = (new EmbeddedArt.inventory_bg() as DisplayObject);
            var _local2:MarginBackground = new MarginBackground(_local1, new Insets(TOP_INSET_HEIGHT));
            this.setBackgroundDecorator(_local2);
            this.setPreferredSize(new IntDimension(_local1.width, (_local1.height + TOP_INSET_HEIGHT)));
        }
        override public function switchType(_arg1:String):void{
            if (this.m_shelf != null){
                this.remove(m_shelfAP);
                m_centerPanel.remove(m_shelf);
            };
            this.m_items = Global.player.inventory.getItems();
            this.m_shelf = new InventoryScrollingList(this.m_items, InventoryCellFactory, 0, 5, 2);
            ASwingHelper.prepare(m_shelf);
            m_centerPanel.append(m_shelf);
            m_centerPanel.setPreferredHeight((((Catalog.CARD_HEIGHT * 2) + CENTER_PANEL_MARGIN) + 36));
            ASwingHelper.prepare(m_centerPanel);
        }
        override protected function get layoutGap():Number{
            return (0);
        }
        protected function onInventoryDown(_arg1:MouseEvent):void{
            var _local6:GMDefault;
            var _local2:GameMode = Global.world.getTopGameMode();
            var _local3:Point = new Point(Global.ui.mouseX, Global.ui.mouseY);
            var _local4:Array = Global.ui.m_bottomUI.getObjectsUnderPoint(_local3);
            var _local5:int;
            _local5 = 0;
            while (_local5 < _local4.length) {
                if ((_local4[_local5] is InventoryCatalogUI)){
                    if ((_local2 is GMDefault)){
                        _local6 = (_local2 as GMDefault);
                        _local6.turnOffObject();
                    };
                    _arg1.stopImmediatePropagation();
                    _arg1.stopPropagation();
                };
                _local5++;
            };
        }
        protected function onInventoryOver(_arg1:MouseEvent):void{
            UI.pushBlankCursor();
        }
        protected function onInventoryOut(_arg1:MouseEvent):void{
            UI.popBlankCursor();
        }
        override public function updateElements():void{
            m_shelf.updateElements();
            this.m_wishlistPane.refreshInventoryLimit();
        }
        override public function refreshShelf():void{
            removeListeners();
            m_centerPanel.remove(m_shelf);
            m_items = Global.player.inventory.getItems();
            m_shelf = new InventoryScrollingList(m_items, InventoryCellFactory, 0, 5, 2);
            ASwingHelper.prepare(m_shelf);
            m_centerPanel.append(m_shelf);
            m_centerPanel.setPreferredHeight((((Catalog.CARD_HEIGHT * 2) + CENTER_PANEL_MARGIN) + 36));
            ASwingHelper.prepare(m_centerPanel);
            addListeners();
            this.refreshInventoryLimit();
        }
        public function refreshInventoryLimit():void{
            this.m_wishlistPane.refreshInventoryLimit();
        }

    }
}//package Display.InventoryUI 
